import React from 'react'
import ReactDOM from 'react-dom/client'
import { BrowserRouter as Router, Routes, Route, Navigate } from 'react-router-dom'
import './index.css'

// 声明全局变量
declare const __PROJECT_TYPE__: string

const loadApp = async () => {
  // 动态导入项目组件
  const { default: MallApp } = await import('./projects/mall/App')
  const { default: AdminApp } = await import('./projects/admin/App')
  
  const App: React.FC = () => {
    return (
      <Router>
        <Routes>
          {/* 前台商城路由 */}
          <Route path="/mall/*" element={<MallApp />} />
          
          {/* 后台管理路由 */}
          <Route path="/admin/*" element={<AdminApp />} />
          
          {/* 默认重定向到前台商城 */}
          <Route path="/" element={<Navigate to="/mall" replace />} />
          
          {/* 其他路径重定向到前台商城 */}
          <Route path="*" element={<Navigate to="/mall" replace />} />
        </Routes>
      </Router>
    )
  }
  
  const root = ReactDOM.createRoot(
    document.getElementById('root') as HTMLElement
  )
  
  root.render(
    <React.StrictMode>
      <App />
    </React.StrictMode>
  )
}

loadApp() 